import 'package:flutter/material.dart';

class ResponsiveUtils {
  // 设备宽度断点
  static const double smallDeviceBreakpoint = 600.0;
  static const double tabletBreakpoint = 768.0;
  static const double largeTabletBreakpoint = 1024.0;

  // 根据设备宽度获取缩放比例
  static double getScaleFactor(BuildContext context) {
    final double deviceWidth = MediaQuery.of(context).size.width;

    if (deviceWidth < smallDeviceBreakpoint) {
      return 0.85; // 小屏设备
    } else if (deviceWidth < tabletBreakpoint) {
      return 0.90; // 中等设备
    } else if (deviceWidth < largeTabletBreakpoint) {
      return 1.0; // 平板设备（10.9寸）
    } else {
      return 1.15; // 大屏设备
    }
  }

  // 获取响应式字体大小
  static double getResponsiveFontSize(BuildContext context, double baseSize) {
    return baseSize * getScaleFactor(context);
  }

  // 获取响应式图标大小
  static double getResponsiveIconSize(BuildContext context, double baseSize) {
    return baseSize * getScaleFactor(context);
  }

  // 获取响应式间距
  static double getResponsiveSpacing(BuildContext context, double baseSpacing) {
    return baseSpacing * getScaleFactor(context);
  }

  // 获取响应式圆角
  static double getResponsiveRadius(BuildContext context, double baseRadius) {
    return baseRadius * getScaleFactor(context);
  }

  // 获取响应式容器尺寸
  static Size getResponsiveContainerSize(BuildContext context, Size baseSize) {
    final scale = getScaleFactor(context);
    return Size(baseSize.width * scale, baseSize.height * scale);
  }

  // 判断设备类型
  static bool isSmallDevice(BuildContext context) {
    return MediaQuery.of(context).size.width < smallDeviceBreakpoint;
  }

  static bool isTablet(BuildContext context) {
    final width = MediaQuery.of(context).size.width;
    return width >= tabletBreakpoint && width < largeTabletBreakpoint;
  }

  static bool isLargeDevice(BuildContext context) {
    return MediaQuery.of(context).size.width >= largeTabletBreakpoint;
  }
}
